/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dw2;
import java.awt.*;
import javax.swing.*;

/**
 *
 * @author Alberto
 */
public abstract class Menu extends JPanel {
    protected Image image;
    protected JPanel contents = new JPanel();
    protected Main parent;
    private boolean empty = true;

    //don't use this; only needed for subclassing
    public Menu() {
        image = null;
        setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
        contents.setLayout(new BoxLayout(contents, BoxLayout.PAGE_AXIS));
        contents.setOpaque(false);
        super.add(Box.createHorizontalGlue());
        super.add(contents);
        super.add(Box.createHorizontalGlue());
    }

    public Menu(Main parent, Image bgImage) {
        this.parent = parent;
        image = bgImage;
        setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
        contents.setLayout(new BoxLayout(contents, BoxLayout.PAGE_AXIS));
        contents.setOpaque(false);
        super.add(Box.createHorizontalGlue());
        super.add(contents);
        super.add(Box.createHorizontalGlue());
    }

    @Override
    public Component add(Component comp) {
        if(empty) {
            contents.add(comp);
            empty = false;
        }
        else {
            contents.add(Box.createRigidArea(new Dimension(0, 10)));
            contents.add(comp);
        }
        return comp;
    }

    @Override
    public void paintComponent(Graphics g) {
        if(image != null) g.drawImage(image, 0, 0, null);

        
    }
}
